package com.fanjia.rabbitmq_producter.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fanjia
 * @className RabbitmqConfig
 * @description TODO
 * @date 2021/4/18 10:02
 */
@Configuration
public class TTLRabbitmqConfig {
    //声明交换机
    @Bean
    public DirectExchange ttlDirectExchange() {
        return new DirectExchange("ttl_direct_order_exchange", true, false);
    }

    //声明队列
    @Bean
    public Queue ttlDirectQueue() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", 5000);
        args.put("x-max-length", 5);//最大接收消息条数。
        args.put("x-dead-letter-exchange", "dead_direct_exchange");
        args.put("x-dead-letter-routing-key", "dead");//fanout不用配置
        return new Queue("ttl.direct.queue", true,false,false,args);
    }

    @Bean
    public Binding ttlDirectDuanxinBinding() {
        return BindingBuilder.bind(ttlDirectQueue()).to(ttlDirectExchange()).with("ttl");
    }


    @Bean
    public Queue ttlMessageDirectQueue() {

        return new Queue("ttl.message.direct.queue", true);
    }

    @Bean
    public Binding ttlMessageDirectDuanxinBinding() {
        return BindingBuilder.bind(ttlMessageDirectQueue()).to(ttlDirectExchange()).with("ttlMessage");
    }





    //


}
